package com.jr.service.impl;

import com.jr.entry.User;
import com.jr.mapper.UserMapper;
import com.jr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean selectByUsername(User user) {
        return userMapper.selectByUsername(user).size()==1?true:false;
    }

    @Override
    public boolean addUser(User user) {
        return userMapper.insertUser(user)==1?true:false;
    }


    /*
    * 返回的是个user对象，
    * 查询user对象的用户名是否为空
    * 为空就表示登陆失败
    * 不为空表示登陆成功
    * */
    @Override
    public boolean selectUser(User user) {

       ArrayList<User> user1 =  userMapper.selectByUsernameAndPassword(user);
       if(!user1.isEmpty()){
           return true;
       }else {
           return false;
       }
//       return (userMapper.selectByUsernameAndPassword(user)).getUid()!=null?true:false;
    }

    /*三选一登录*/
    @Override
    public ArrayList<User> selectUserByOne(User user) {
      ArrayList<User> list = userMapper.selectUser(user);
        return list;
    }
    /*主页传值登录*/
    @Override
    public ArrayList<User> userLogin(User user) {
        ArrayList<User> list = userMapper.userLogin(user);
        return list;
    }

    @Override
    public User forgetlogin(User user) {
        System.out.println("service："+userMapper.selectForgetUser(user));
        return userMapper.selectForgetUser(user);
    }

    @Override
    public Boolean updatepassword(User user) {
        return userMapper.updateUser(user)!=0?true:false;
    }
}
